/*
 * ComponentClone.java
 *
 * Created on June 6, 2006, 10:54 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author Timoz
 */

import javax.swing.*;

public class ComponentClone {
    
    /** Creates a new instance of ComponentClone */
    public ComponentClone() {
    }
    
    public static MyComponentContainer clone (MyComponentContainer component)
    {
        MyComponentContainer clonedComponent=null;
        
        if (component instanceof MyTextFieldContainer)
        {
        clonedComponent = new MyTextFieldContainer (((JTextField)component.getComponent()).getText(),component.frame);
        ((JTextField)clonedComponent.getComponent()).setSize(((JTextField)component.getComponent()).getSize());
        ((JTextField)clonedComponent.getComponent()).setBorder(((JTextField)component.getComponent()).getBorder());
        ((JTextField)clonedComponent.getComponent()).setBackground(((JTextField)component.getComponent()).getBackground());
        ((JTextField)clonedComponent.getComponent()).setFont(((JTextField)component.getComponent()).getFont());
        ((JTextField)clonedComponent.getComponent()).setForeground(((JTextField)component.getComponent()).getForeground());
        ((JTextField)clonedComponent.getComponent()).setHorizontalAlignment(((JTextField)component.getComponent()).getHorizontalAlignment());
        ((JTextField)clonedComponent.getComponent()).setLocation(((JTextField)component.getComponent()).getLocation());
        }
        
        else if (component instanceof MyLabelContainer)
        {
        clonedComponent = new MyLabelContainer (((JLabel)component.getComponent()).getText(),component.frame);
        ((JLabel)clonedComponent.getComponent()).setSize(((JLabel)component.getComponent()).getSize());
        ((JLabel)clonedComponent.getComponent()).setBorder(((JLabel)component.getComponent()).getBorder());
        ((JLabel)clonedComponent.getComponent()).setBackground(((JLabel)component.getComponent()).getBackground());
        ((JLabel)clonedComponent.getComponent()).setFont(((JLabel)component.getComponent()).getFont());
        ((JLabel)clonedComponent.getComponent()).setForeground(((JLabel)component.getComponent()).getForeground());
        ((JLabel)clonedComponent.getComponent()).setIcon(((JLabel)component.getComponent()).getIcon());
        ((JLabel)clonedComponent.getComponent()).setHorizontalAlignment(((JLabel)component.getComponent()).getHorizontalAlignment()); 
        ((JLabel)clonedComponent.getComponent()).setVerticalAlignment(((JLabel)component.getComponent()).getVerticalAlignment());
        ((JLabel)clonedComponent.getComponent()).setLocation(((JLabel)component.getComponent()).getLocation());
        ((MyLabelContainer)clonedComponent).setBorderWidth(((MyLabelContainer)component).getBorderWidth());
        ((MyLabelContainer)clonedComponent).setPhotoPath(((MyLabelContainer)component).getPhotoPath());
        }
        
        else if (component instanceof MyButtonContainer)
        {
        clonedComponent = new MyButtonContainer (((JButton)component.getComponent()).getText(),component.frame);
        ((JButton)clonedComponent.getComponent()).setSize(((JButton)component.getComponent()).getSize());
        ((JButton)clonedComponent.getComponent()).setBorder(((JButton)component.getComponent()).getBorder());
        ((JButton)clonedComponent.getComponent()).setBackground(((JButton)component.getComponent()).getBackground());
        ((JButton)clonedComponent.getComponent()).setFont(((JButton)component.getComponent()).getFont());
        ((JButton)clonedComponent.getComponent()).setForeground(((JButton)component.getComponent()).getForeground());
        ((JButton)clonedComponent.getComponent()).setIcon(((JButton)component.getComponent()).getIcon());
        ((JButton)clonedComponent.getComponent()).setHorizontalAlignment(((JButton)component.getComponent()).getHorizontalAlignment()); 
        ((JButton)clonedComponent.getComponent()).setVerticalAlignment(((JButton)component.getComponent()).getVerticalAlignment());
        ((JButton)clonedComponent.getComponent()).setLocation(((JButton)component.getComponent()).getLocation());
        ((MyButtonContainer)clonedComponent).setOperation(((MyButtonContainer)component).getOperation());
        }
        
        else if (component instanceof MyToggleButtonContainer)
        {
        clonedComponent = new MyToggleButtonContainer (((JToggleButton)component.getComponent()).getText(),component.frame);
        ((JToggleButton)clonedComponent.getComponent()).setSize(((JToggleButton)component.getComponent()).getSize());
        ((JToggleButton)clonedComponent.getComponent()).setBorder(((JToggleButton)component.getComponent()).getBorder());
        ((JToggleButton)clonedComponent.getComponent()).setBackground(((JToggleButton)component.getComponent()).getBackground());
        ((JToggleButton)clonedComponent.getComponent()).setFont(((JToggleButton)component.getComponent()).getFont());
        ((JToggleButton)clonedComponent.getComponent()).setForeground(((JToggleButton)component.getComponent()).getForeground());
        ((JToggleButton)clonedComponent.getComponent()).setIcon(((JToggleButton)component.getComponent()).getIcon());
        ((JToggleButton)clonedComponent.getComponent()).setHorizontalAlignment(((JToggleButton)component.getComponent()).getHorizontalAlignment()); 
        ((JToggleButton)clonedComponent.getComponent()).setVerticalAlignment(((JToggleButton)component.getComponent()).getVerticalAlignment());
        ((JToggleButton)clonedComponent.getComponent()).setLocation(((JToggleButton)component.getComponent()).getLocation());
        }
        
        else if (component instanceof MyCheckBoxContainer)
        {
        clonedComponent = new MyCheckBoxContainer (component.frame);
        ((JCheckBox)clonedComponent.getComponent()).setSize(((JCheckBox)component.getComponent()).getSize());
        ((JCheckBox)clonedComponent.getComponent()).setBorder(((JCheckBox)component.getComponent()).getBorder());
        ((JCheckBox)clonedComponent.getComponent()).setBackground(((JCheckBox)component.getComponent()).getBackground());
        ((JCheckBox)clonedComponent.getComponent()).setForeground(((JCheckBox)component.getComponent()).getForeground());
        ((JCheckBox)clonedComponent.getComponent()).setHorizontalAlignment(((JCheckBox)component.getComponent()).getHorizontalAlignment()); 
        ((JCheckBox)clonedComponent.getComponent()).setVerticalAlignment(((JCheckBox)component.getComponent()).getVerticalAlignment());
        ((JCheckBox)clonedComponent.getComponent()).setLocation(((JCheckBox)component.getComponent()).getLocation());
        }
        
        else if (component instanceof MyRadioButtonContainer)
        {
        clonedComponent = new MyRadioButtonContainer (component.frame);
        ((JRadioButton)clonedComponent.getComponent()).setSize(((JRadioButton)component.getComponent()).getSize());
        ((JRadioButton)clonedComponent.getComponent()).setBorder(((JRadioButton)component.getComponent()).getBorder());
        ((JRadioButton)clonedComponent.getComponent()).setBackground(((JRadioButton)component.getComponent()).getBackground());
        ((JRadioButton)clonedComponent.getComponent()).setForeground(((JRadioButton)component.getComponent()).getForeground());
        ((JRadioButton)clonedComponent.getComponent()).setHorizontalAlignment(((JRadioButton)component.getComponent()).getHorizontalAlignment()); 
        ((JRadioButton)clonedComponent.getComponent()).setVerticalAlignment(((JRadioButton)component.getComponent()).getVerticalAlignment());
        ((JRadioButton)clonedComponent.getComponent()).setLocation(((JRadioButton)component.getComponent()).getLocation());
        }
        
        else if (component instanceof MyPictureContainer)
        {
        clonedComponent = new MyPictureContainer (((JLabel)component.getComponent()).getText(),component.frame);
        ((JLabel)clonedComponent.getComponent()).setSize(((JLabel)component.getComponent()).getSize());
        ((JLabel)clonedComponent.getComponent()).setBorder(((JLabel)component.getComponent()).getBorder());
        ((JLabel)clonedComponent.getComponent()).setBackground(((JLabel)component.getComponent()).getBackground());
        ((JLabel)clonedComponent.getComponent()).setFont(((JLabel)component.getComponent()).getFont());
        ((JLabel)clonedComponent.getComponent()).setForeground(((JLabel)component.getComponent()).getForeground());
        ((JLabel)clonedComponent.getComponent()).setIcon(((JLabel)component.getComponent()).getIcon());
        ((JLabel)clonedComponent.getComponent()).setHorizontalAlignment(((JLabel)component.getComponent()).getHorizontalAlignment()); 
        ((JLabel)clonedComponent.getComponent()).setVerticalAlignment(((JLabel)component.getComponent()).getVerticalAlignment());
        ((JLabel)clonedComponent.getComponent()).setLocation(((JLabel)component.getComponent()).getLocation());
        }
        
        else if (component instanceof MyComboBoxContainer)
        {
        clonedComponent = new MyComboBoxContainer (component.getName(),component.frame);
        ((JComboBox)clonedComponent.getComponent()).setSize(((JComboBox)component.getComponent()).getSize());
        ((JComboBox)clonedComponent.getComponent()).setBorder(((JComboBox)component.getComponent()).getBorder());
        ((JComboBox)clonedComponent.getComponent()).setBackground(((JComboBox)component.getComponent()).getBackground());
        ((JComboBox)clonedComponent.getComponent()).setFont(((JComboBox)component.getComponent()).getFont());
        ((JComboBox)clonedComponent.getComponent()).setForeground(((JComboBox)component.getComponent()).getForeground());
        ((JComboBox)clonedComponent.getComponent()).setLocation(((JComboBox)component.getComponent()).getLocation());
        }
        
        else if (component instanceof MyListContainer)
        {
        clonedComponent = new MyListContainer (component.getName(),component.frame);
        ((JList)clonedComponent.getComponent()).setSize(((JList)component.getComponent()).getSize());
        ((JList)clonedComponent.getComponent()).setBorder(((JList)component.getComponent()).getBorder());
        ((JList)clonedComponent.getComponent()).setBackground(((JList)component.getComponent()).getBackground());
        ((JList)clonedComponent.getComponent()).setFont(((JList)component.getComponent()).getFont());
        ((JList)clonedComponent.getComponent()).setForeground(((JList)component.getComponent()).getForeground());
        ((JList)clonedComponent.getComponent()).setLocation(((JList)component.getComponent()).getLocation());
        }
        
        clonedComponent.setName(component.getName());
        return clonedComponent;
    }
    
}
